package pjaws;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

public class PjawsShell {

	private Vector<String[]> SCPPairs;

	public PjawsShell() {
		SCPPairs = new Vector<String[]>();
	}

	public void addSCPPair(String source, String destination) {
		String[] pair = { source, destination };
		SCPPairs.add(pair);
	}

	public void runSCPs() {
		for (int i = 0; i < SCPPairs.size(); i++) {
			String[] pair = SCPPairs.get(i);
			String cmd = "scp " + pair[0] + " " + pair[1];
			execCmd(cmd);
		}

	}

	public void execCmd(String cmd) {
		String s = null;

		System.out.println("-------" + cmd + "---------");

		try {

			Process p = Runtime.getRuntime().exec(cmd);

			BufferedReader stdInput = new BufferedReader(new InputStreamReader(
					p.getInputStream()));

			BufferedReader stdError = new BufferedReader(new InputStreamReader(
					p.getErrorStream()));

			// read the output from the command
			System.out.println("Here is the standard output of the command:\n");
			while ((s = stdInput.readLine()) != null) {
				System.out.println(s);
			}

			// read any errors from the attempted command
			System.out
					.println("Here is the standard error of the command (if any):\n");
			while ((s = stdError.readLine()) != null) {
				System.out.println(s);
			}

		} catch (IOException e) {
			System.out.println("exception happened - here's what I know: ");
			e.printStackTrace();
		}
		System.out.println("----------------------------------------------");

	}

}
